module ImageFiles
  class ImageUpload
    def initialize(obj, img)
      write_to_local(obj, img)
    end

    private
    def write_to_local(obj, img)
      path = "public/uploads/#{obj.class.name.underscore}/imgs/#{obj.id}/".freeze
      if !File.exist? path
        FileUtils.mkdir_p(path)
      end
      open("#{path}logo.png", "wb") do |f|
        f.write(img.read)
      end
    end

  end
end
